﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewsMine.DomainObjects;
using NewsMine.Storage;

namespace NewsDiscoveryEngine
{
    [Serializable]
    public class SaveHtmlFeedItemToMainStoreJob : BaseJob
    {
        public FeedItem FeedItem { get; set; }
        public override bool ExecuteJob()
        {
            //save htmlFeedItem to the main store and also create a IndexHtmlFeedItemJob
            FeedItem = SaveTitleAndLinkForDeduplicationPurpose(FeedItem);

            ProcessOutput(FeedItem);

            return true;

        }

        public static FeedItem SaveTitleAndLinkForDeduplicationPurpose(FeedItem feedItem)
        {
           // feedItem.ID = Guid.NewGuid().ToString("N");
      

            Defaults.UniqueHtmlFeedLinkStore.Replace(NewsMine.Utilities.TempAnalyzer.RemoveAllSpecialCharacterForIndexing(feedItem.Link).Replace(" ",string.Empty), 0);
            Defaults.UniqueHtmlFeedLinkStore.Close();



            if (!string.IsNullOrEmpty(feedItem.Title) && !string.IsNullOrEmpty(feedItem.Title.Trim()))
            {
                Defaults.UniqueTitleStore.Replace(NewsMine.Utilities.TempAnalyzer.RemoveAllSpecialCharacterForIndexing(feedItem.Title).Replace(" ",string.Empty), 0);
                Defaults.UniqueTitleStore.Close();
            }

            return feedItem;
        }

    }
}
